{include file="public/layout" /}
<body>
  <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
          <div class="layui-col-md12">
            <div class="layui-card">
              <div class="layui-card-body web-system" pad15>
                <div class="layui-form" wid100 lay-filter="">
                  <div class="layui-form-item">
                    <label class="layui-form-label"><b>*</b>模型名称</label>
                    <div class="layui-input-inline">
                      <input type="text" name="ntitle" value="{$field.ntitle|default=''}" id="ntitle" class="layui-input" lay-verify="required">
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">模型标识</label>
                    <div class="layui-input-inline">
                        <div style="padding:6px 0px;">{$field.nid}</div>
                        <input type="hidden" name="nid" value="{$field.nid|default=''}">
                    </div>
                    <div class="layui-form-inline2">
                        与文档的模板相关连，建议由小写字母、数字组成，因为部份Unix系统无法识别中文文件。<br/>
                        列表模板是：lists_模型标识.htm<br/>
                        文档模板是：view_模型标识.htm
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">允许标题重复</label>
                    <div class="layui-input-inline w70">
                        <input type="checkbox" lay-filter="is_repeat_title" lay-skin="switch" lay-text="是|否" {if condition="!isset($field.is_repeat_title) || $field.is_repeat_title eq 1"}checked{/if}>
                        <input type="hidden" name="is_repeat_title" value="{$field.is_repeat_title|default='1'}" />
                    </div>
                  </div>
                    {notempty name="$list"}
                    <div class="layui-form-item">
                        <label class="layui-form-label">关联{$list.ntitle}</label>
                        <div class="layui-input-inline">
                            <select id="join_id" name="join_id"  lay-filter="join_id">
                                <option value="0" >不关联</option>
                                <option value="{$list.id}"  {eq name="$field.join_id" value="$list.id" } selected {/eq} >关联</option>
                            </select>
                        </div>
                        <div class="layui-input-inline layui-btn-container " style="width: auto;">
                            <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                            <div class="layui-form-inline2 ey_helptips_txt">关联模型</div>
                        </div>
                    </div>
                    {/notempty}
                    <div id="join_must_div" class="layui-form-item" {empty name="$field.join_id"}style="display: none;"{/empty}>
                        <label class="layui-form-label">关联必选</label>
                        <div class="layui-input-inline w70">
                            <input type="checkbox" lay-filter="join_must" lay-skin="switch" lay-text="是|否" {if condition="$field.join_must eq 1"}checked{/if}>
                            <input type="hidden" name="join_must" value="{$field.join_must|default='0'}" />
                        </div>
                        <div class="layui-input-inline layui-btn-container " style="width: auto;">
                            <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                            <div class="layui-form-inline2 ey_helptips_txt">添加、编辑内容时，是否必须选择{$list.ntitle}</div>
                        </div>
                    </div>
                  {notempty name="$field.ifsystem"}
                    <div class="layui-form-item">
                        <label class="layui-form-label">关联经纪人</label>
                        <div class="layui-input-inline w70">
                            <input type="checkbox" lay-filter="is_join_user" lay-skin="switch" lay-text="是|否" {if condition="!isset($field.is_join_user) || $field.is_join_user eq 1"}checked{/if}>
                            <input type="hidden" name="is_join_user" value="{$field.is_join_user|default='0'}" />
                        </div>
                    </div>
                  {/notempty}

                    <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="hidden" name="id" value="{$field.id}">
                        <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
                    </div>
                  </div>
              </div>
            </div>
          </div>
        </div>
  </div>

  <script>
  layui.config({
    base: '__SKIN__/' //静态资源所在路径
    ,version: '{$version}'
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set'], function(){
    var $ = layui.$
    ,layer = layui.layer
    ,form = layui.form;

    var parentObj = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

    // 监听开关
    form.on('switch', function(data){
      var elemId = data.elem.attributes['lay-filter']['nodeValue'];
      if (data.elem.checked) {
        this.value = 1;
      } else {
        this.value = 0;
      }
      $("input[name='"+elemId+"']").val(this.value);
    });
    //选中选择关联
      form.on('select(join_id)', function(data){
          if (data.value == 0){ //隐藏
              $("#join_must_div").hide();
          }else{
              $("#join_must_div").show();
          }
          form.render();
      });
    //监听提交
    form.on('submit(formSubmit)', function(data){
        var load = layer_loading();
        data.field._ajax = 1;
        $.ajax({
            type : 'post',
            url : "{:url('Channeltype/edit')}",
            data : data.field,
            dataType : 'json',
            success : function(res){
                layer.close(load); //关闭loading
                if(res.code == 1){
                    layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                        parent.gourl(res.url);
                    });
                }else{
                    parent.showErrorMsg(res.msg);
                }
            },
            error: function(e){
                layer.close(load); //关闭loading
                showErrorAlert();
            }
        });
        return false;
    });

  });

  </script>
{include file="public/footer" /}